#include <iostream>
#include <vector>
#include <map>

using namespace std;

int timeDiff(string i, string j){
    int diff = j[0] - i[0];
    int td = diff * 10 + (j[1] - i[1]);
    diff = j[3] - i[3];
    td = td * 60 + diff * 10 + (j[4] - i[4]);
    return td < 720 ? td : 1440 - td;
}

int findMinDifference(vector<string>& timePoints) {
    map<string, int> mp;
    for(string st : timePoints){
        auto it = mp.insert({st, 1});
        if(!it.second) return 0;
    }
    auto pre = mp.begin(), next = pre, end = mp.end(); end--; int minDiff = timeDiff(pre->first, end->first);
    while(++next != mp.end()){
        int td = timeDiff(pre->first, next->first);
        if(minDiff > td) minDiff = td;
        pre = next;
    }
    return minDiff;
}

int main(){
    // vector<string> timePoints = { "00:00", "23:59", "01:30", "16:15" };
    vector<string> timePoints = { "01:01","02:01","03:00" };
    cout << findMinDifference(timePoints) << endl;
    return 0;
}
